home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 2002 Tom Parker (tom@carrott.org),
- Matthias Münch (matthias@amigaworld.de)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- In addition, as a special exception, Tom Parker and Matthias Münch give
- permission to link the code of this program with a TCP stack of your
- choice, any official MUI libraries or classes and any custom MUI classes
- that should be necessary for the operation of this program. This
- exception also gives you permission to distribute linked combinations
- including this software with any of the before-mentioned libraries and
- classes. You must obey the GNU General Public License in all respects for
- all of the code used other than that provided by the before-mentioned
- libraries and classes. As part of this exception you are obliged to
- follow the license terms of the before-mentioned libraries, this license
- does not compel you to follow those terms, but if you do not then you may
- not link with those libraries. If you modify this file, you may extend
- this exception to your version of the file, but you are not obligated to
- do so. If you do not wish to do so, delete this exception statement from
- your version.
- */
- /*
- ** presence subscription requests
- */
-
- #include "common.h"
-
- #include <MUI/NListview_mcc.h>
-
- static Object *p_list = NULL;
-
- static ULONG presence_new(struct IClass *cl, Object *obj, struct opSet *msg);
- static MUI_LIST_DISP_DECL(presence_disp, ikspak *pak);
-
-
- MUI_DISPATCH(presence_dispatch)
- {
- switch(msg->MethodID)
- {
- case OM_NEW:
- return presence_new(cl,obj,(APTR)msg);
-
- case PRESENCE_BUTTON:
- {
- u_long tmp;
- ikspak *pak;
- iks *x;
-
- GetAttr(MUIA_NList_EntryClick, p_list, &tmp);
- if(tmp == -1 || tmp == -2) return;
- DoMethod(p_list, MUIM_NList_GetEntry, tmp, &pak);
- if (!pak) {
- return 0;
- }
-
- if(((int)MARG1) == 0)
- {
- x = iks_make_pres(IKS_TYPE_SUBSCRIBED, 0, iks_id_print(pak->from), NULL);
- }
- else
- {
- x = iks_make_pres(IKS_TYPE_UNSUBSCRIBED, 0, iks_id_print(pak->from), NULL);
- }
- iks_send(net.parser, x);
- iks_delete(x);
-
- DoMethod(p_list, MUIM_NList_Remove, tmp);
-
- return 0;
- }
-
- }
- return DoSuperMethodA(cl, obj, msg);
- }
-
-
- static ULONG presence_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- static struct Hook dispHook = { {0,0}, &presence_disp, NULL, NULL };
- Object *acceptbut, *rejectbut;
-
- obj = (Object *)DoSuperNew(cl,obj,
- MUIA_Window_ID, MAKE_ID('P', 'R', 'E', 'S'),
- MUIA_Window_Title, MSG_PRESENCE_TITLE,
- MUIA_HelpNode, "window-subscriptions",
- WindowContents, VGroup,
- Child, NListviewObject,
- MUIA_NListview_NList, (ULONG) p_list = NListObject,
- InputListFrame,
- MUIA_NList_Title, TRUE,
- MUIA_NList_Format, "BAR,",
- MUIA_NList_DisplayHook, &dispHook,
- MUIA_CycleChain, 1,
- End,
- End,
- Child, HGroup,
- Child, acceptbut = mui_button(MSG_PRESENCE_ACCEPT_GAD),
- Child, mui_button("Accept & Subscribe"),
- Child, rejectbut = mui_button(MSG_PRESENCE_REJECT_GAD),
- End,
- End,
- TAG_MORE, msg->ops_AttrList);
-
- if(!obj) return(0);
-
- DoMethod(acceptbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 2, PRESENCE_BUTTON, 0);
- DoMethod(rejectbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 2, PRESENCE_BUTTON, 1);
-
- DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj, 3, MUIM_Set, MUIA_Window_Open, FALSE);
-
- return (ULONG)obj;
- }
-
-
- MUI_LIST_DISP_STATIC(presence_disp, ikspak *pak)
- {
- if(pak) {
- *array++ = iks_pool_strdup(pak->p, convert_locale(iks_id_print(pak->from)));
- *array = iks_pool_strdup(pak->p, convert_locale(iks_find_cdata(pak->x, "status")));
- }
- else
- {
- *array++ = MSG_PRESENCE_COL_JABBER_ID;
- *array = MSG_PRESENCE_COL_GREETING;
- }
-
- return 0;
- }
-
-
- void presence_ask(ikspak *pak)
- {
- u_long tmp;
- int entry;
- ikspak *listpak = NULL;
- BOOL duplicate = FALSE;
-
- if(pak->subtype != IKS_TYPE_SUBSCRIBE)
- {
- /* FIX ME */
- return;
- }
-
- get(p_list, MUIA_NList_Entries, &tmp);
- for (entry = 0; entry < tmp; entry++) {
- DoMethod(p_list, MUIM_NList_GetEntry, entry, &listpak);
- if (listpak) {
- if (iks_id_cmp(pak->from,listpak->from) == 0) {
- duplicate = TRUE;
- break;
- }
- }
- }
-
- if (!(duplicate)) {
- DoMethod(p_list, MUIM_NList_InsertSingle, pak, MUIV_NList_Insert_Bottom);
- }
- get(gui.preswin, MUIA_Window_Open, &tmp);
- if(!tmp) set(gui.preswin, MUIA_Window_Open, TRUE);
- }
-